Skip to content

Python: Make workspace file hooks opt-in for GitHubCopilotAgent - #7517

Open
giles17 wants to merge 1 commit into
microsoft:mainfrom
giles17:session-option-defaults
Open

Python: Make workspace file hooks opt-in for GitHubCopilotAgent#7517
giles17 wants to merge 1 commit into
microsoft:mainfrom
giles17:session-option-defaults

Conversation

@giles17

@giles17 giles17 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

GitHubCopilotAgent session behavior depends on which working directory the agent runs in. The Copilot CLI loads file hooks from a checkout's .github/hooks/, controlled by the SDK enable_file_hooks session option, and the agent never sets it, so it inherits the runtime default.

That makes runs harder to reason about and reproduce: the same agent, the same options, and the same prompt can behave differently based only on the directory the process started in. It is also invisible to callers, since it sits outside the small set of options the agent gives an explicit default.

Description & Review Guide

  • What are the major changes?

    • _build_session_kwargs now applies an explicit default for enable_file_hooks (False), alongside the existing on_permission_request default. The defaults live in a module-level _WORKSPACE_CONFIG_DEFAULTS map so future additions have one home.
    • The default is applied only when the resolved value is None, so an explicit True or False from either default_options or per-run options is preserved.
    • enable_file_hooks is now a documented GitHubCopilotOptions key.
    • README gains a short section describing the option and how to opt in; the package AGENTS.md records the convention.
  • What is the impact of these changes?

    • Sessions behave consistently regardless of the checkout they run in.
    • This changes a default: callers who currently rely on .github/hooks/ definitions being picked up automatically need enable_file_hooks=True in default_options or per-run options. Nothing else on the wire changes, and the on_permission_request / on_pre_tool_use paths are untouched.
    • Options that only shape prompt context, such as enable_host_git_operations, are deliberately left alone so prompt quality is unaffected.
    • One existing test used assert_called_once_with on resume_session and needed the new kwarg added; that is a strict-matcher update, not a behavior change.
  • What do you want reviewers to focus on?

    • Whether False is the right default for enable_file_hooks, and whether the opt-in path reads clearly in the README.

Related Issue

Fixes #7516

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Session behavior currently varies with the working directory the agent runs
in, because the CLI picks up file hook definitions from the checkout. Give
`enable_file_hooks` an explicit default of False in `_build_session_kwargs`
so a session behaves consistently regardless of the checkout, and let callers
opt in through `default_options` or per-run options.

Add the option to `GitHubCopilotOptions` with documentation, and cover the
default, the opt-in, and the per-run override with tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 42d0b850-56e0-4346-9b3e-cc3de339b16b
Copilot AI lite review requested due to automatic review settings August 4, 2026 20:48
@giles17
giles17 temporarily deployed to github-app-auth August 4, 2026 20:48 — with GitHub Actions Inactive
@giles17
giles17 temporarily deployed to github-app-auth August 4, 2026 20:48 — with GitHub Actions Inactive
@giles17
giles17 temporarily deployed to github-app-auth August 4, 2026 20:48 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/github_copilot/agent_framework_github_copilot
   _agent.py4372294%70–71, 113, 122–124, 128, 566, 581–582, 661, 674, 811, 815, 984, 1018–1019, 1058, 1061, 1198, 1277, 1295
TOTAL44677410490% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9134 34 💤 0 ❌ 0 🔥 2m 28s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes GitHubCopilotAgent session behavior deterministic across working directories by explicitly defaulting workspace-driven Copilot SDK session options (starting with enable_file_hooks) to opt-in, preventing implicit .github/hooks/ influence unless callers request it.

Changes:

  • Add a module-level _WORKSPACE_CONFIG_DEFAULTS map and apply its defaults in _build_session_kwargs when the resolved option value is None.
  • Document enable_file_hooks as a supported GitHubCopilotOptions key and explain the opt-in behavior and security considerations.
  • Update and add unit tests to validate the new default and precedence rules (runtime options override agent defaults).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
python/packages/github_copilot/agent_framework_github_copilot/_agent.py Introduces _WORKSPACE_CONFIG_DEFAULTS, documents enable_file_hooks, and applies an explicit default in session kwargs construction.
python/packages/github_copilot/tests/test_github_copilot_agent.py Updates strict resume-session assertion and adds tests covering default/off + override precedence for enable_file_hooks.
python/packages/github_copilot/README.md Documents workspace-driven options and how to opt into enable_file_hooks.
python/packages/github_copilot/AGENTS.md Records the convention for session option defaults and where to add future workspace-driven defaults.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 2 | Confidence: 93% | Result: All clear

Reviewed: Correctness, Test Coverage


Automated review by giles17's agents

@giles17
giles17 marked this pull request as ready for review August 4, 2026 20:56
@giles17
giles17 temporarily deployed to github-app-auth August 4, 2026 20:56 — with GitHub Actions Inactive

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 2 | Confidence: 70% | Result: All clear

Reviewed: Correctness, Test Coverage


Automated review by giles17's agents

# the CLI does on the host. The agent leaves them off so a session behaves the same way in
# every checkout; callers that want the checkout-driven behavior can turn each one back on
# through ``default_options`` or per-run options.
_WORKSPACE_CONFIG_DEFAULTS: dict[str, bool] = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we preserve the existing default or treat this as an explicit breaking migration? With the pinned SDK/CLI, omitting enable_file_hooks loads repository hooks, while this explicit False disables them. Existing consumers of this stable package will silently stop running .github/hooks/ after upgrading unless they discover and add the new opt-in.

# the CLI does on the host. The agent leaves them off so a session behaves the same way in
# every checkout; callers that want the checkout-driven behavior can turn each one back on
# through ``default_options`` or per-run options.
_WORKSPACE_CONFIG_DEFAULTS: dict[str, bool] = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to keep the enable_file_hooks=False default inside _build_session_kwargs until we have a second workspace-controlled option? At the moment, _WORKSPACE_CONFIG_DEFAULTS only contains a single value and has a single caller. Removing it simplifies the code to a single conditional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: GitHubCopilotAgent session behavior varies with the working directory

3 participants